package com.example.goodsass.common;


import lombok.Data;

import java.io.Serializable;

@Data
public class BaseResponse<T> implements Serializable {

    private int code;

    private T data;

    private String message;

    public BaseResponse(int code, T data, String message) {
        this.code = code;
        this.data = data;
        this.message = message;
    }

    public BaseResponse(int code, T data) {
        this(code, data, "");
    }

    public BaseResponse(ErrorCode errorCode) {
        this(errorCode.getCode(), null, errorCode.getMessage());
    }

    public static <T> BaseResponse<T> success(T data,String message) {
        return new BaseResponse<>(0, data, message);
    }

    public static <T> BaseResponse<T> success(T data) {
        return new BaseResponse<>(0, data, "");
    }

    public static BaseResponse<?> error(ErrorCode errorCode, String msg) {
        return new BaseResponse<>(errorCode.getCode(), null, msg);
    }

    public static BaseResponse<?> error(int errorCode, String msg) {
        return new BaseResponse<>(errorCode, null, msg);
    }
}


